<template>
  <div class="login">
    <div class="info">
      <div class="title">
        <p>登录</p>
      </div>
      <div class="item">
        <i class="name"></i>
        <input v-model="info.phone" placeholder="账号">
      </div>
      <div class="item">
        <i class="pwd"></i>
        <input v-model="info.password" type="password" placeholder="密码">
      </div>
      <div class="update">
        <button class="update_btn" @click="login">登录</button>
      </div>
    </div>
  </div>
</template>

<script>
  import {setCookie} from '../util/cookie'

  export default {
    name: "login",
    data() {
      return {
        info: {
          phone: '',
          password: ''
        }
      }
    },
    methods: {
      login() {
        if (this.info.phone.length <= 4) {
          this.$message({message: '请检查用户名', type: 'warning'})
          return
        }
        if (this.info.password.length <= 4) {
          this.$message({message: '请检查你的密码', type: 'warning'})
          return
        }

        this.$post('/user/manager/admin/login', this.info, res => {
          this.$message({message: '登录成功', type: 'success'})
          this.$store.commit('SET_TOKEN', res.token)
          this.$store.commit('SET_NAME', res.userName)
          this.$store.commit('SET_SIGN', res.sign)
          // setCookie('token',res.token)
          setCookie('name', res.userName)
          setCookie('sign', res.sign)
          this.$router.push('/admin/')
        })
      }
    }
  }
</script>

<style scoped>

  .login {
    margin: 0 auto;
    margin-top: 40px;
  }

  .login > .info {
    width: 300px;
    margin: 0 auto;
  }

  .login > .info > .item {
    margin-bottom: 20px;
    position: relative;
    border: 1px solid #0078ff;
    height: 40px;
    width: 100%;
  }

  .info > .title > p {
    font-size: 30px;
    font-weight: 800;
    text-align: center;
  }

  .login > .info > .item > i {
    position: absolute;
    z-index: 3;
    top: 0;
    left: 0;
    width: 40px;
    height: 40px;
    border-right: 1px solid #0078ff;
    background-color: #0078ff;
  }

  .info > .item > i.name {
    background: url('../assets/user.png') no-repeat;
    background-size: 68%;
    background-position: 7px 6px;
  }

  .info > .item > i.pwd {
    background: url('../assets/pwd.png') no-repeat;
    background-size: 68%;
    background-position: 7px 6px;
  }

  .info > .item > input {
    line-height: 18px;
    height: 18px;
    border: 0;
    padding-left: 51px;
    width: 248px;
    float: none;
    overflow: hidden;
    font-size: 14px;
    height: 38px;
    outline: none;
  }

  .info > .update {
    width: 100%;
    margin-top: 50px;
  }

  .info > .update > .update_btn {
    width: 100%;
    height: 40px;
    background-color: #0078ff;
    color: white;
    border: none;
    cursor: pointer;
    font-size: 18px;
  }
</style>
